﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FGrubert.VpcManager
{
    public partial class FrmFolders : Form
    {
        public FrmFolders()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Show folder browser and add the path to the list
        /// </summary>
        private void btnAddFolder_Click(object sender, EventArgs e)
        {
            if (dlgFolderBrowser.ShowDialog(this) == DialogResult.OK)
            {
                lstFolders.Items.Add(dlgFolderBrowser.SelectedPath);
            }
        }

        /// <summary>
        /// Remove the selected items
        /// </summary>
        private void btnRemoveFolder_Click(object sender, EventArgs e)
        {
            while (lstFolders.SelectedItems.Count > 0)
            {
                lstFolders.Items.Remove(lstFolders.SelectedItems[0]);
            }
        }

        /// <summary>
        /// Save the list and close the file
        /// </summary>
        private void btnOK_Click(object sender, EventArgs e)
        {
            Properties.Settings settings = Properties.Settings.Default;
            settings.SearchFolders = new System.Collections.Specialized.StringCollection();
            foreach (string folder in lstFolders.Items)
            {
                settings.SearchFolders.Add(folder);
            }
            settings.Save();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        /// <summary>
        /// Load the current settings
        /// </summary>
        private void FrmFolders_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.SearchFolders == null)
            {
                Properties.Settings settings = Properties.Settings.Default;
                settings.SearchFolders = new System.Collections.Specialized.StringCollection();
                settings.Save();
            }
            foreach (string folder in Properties.Settings.Default.SearchFolders)
            {
                lstFolders.Items.Add(folder);
            }
        }
    }
}
